#include <irrlicht.h>

using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;

#ifdef _IRR_WINDOWS_
#pragma comment(lib, "Irrlicht.lib")
#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")
#endif

bool keys[KEY_KEY_CODES_COUNT];

class MyEventReceiver : public IEventReceiver { 
 public: 
  virtual bool OnEvent(const SEvent & event){ 
  if(event.EventType == irr::EET_KEY_INPUT_EVENT){ 
	keys[event.KeyInput.Key] = event.KeyInput.PressedDown; 
	return false; 
  } 
	return false; 
  } 
}; 


int main(){

	
	//create new device and get pointer to it
	IrrlichtDevice *device = createDevice(EDT_OPENGL, dimension2d<u32>(640,480), 16, false, false, false, 0);
	if(!device){return 1;}
	//get video driver pointer
	IVideoDriver* driver = device->getVideoDriver(); 
	//get scene manager pointer
	ISceneManager* smgr = device->getSceneManager();
	//setup event receiver
	MyEventReceiver rv; 
	device->setEventReceiver(&rv);

	ISceneNode * cube = smgr->addCubeSceneNode();
	cube->setPosition(vector3df(0,5,5));

	ICameraSceneNode* cam = smgr->addCameraSceneNodeFPS();
	device->getCursorControl()->setVisible(false);
	
	smgr->addSkyDomeSceneNode(driver->getTexture("media/skydome.jpg"),16,16,1.0f,1.0f);

	int lastFPS = -1;
	//game loop
	while(device->run()){
		driver->beginScene(true, true, SColor(255,100,101,140));
		smgr->drawAll();
		driver->endScene();
		int fps = driver->getFPS();
        if (lastFPS != fps){
			core::stringw str = L"Life-Sim [";
            str += driver->getName();
            str += "] FPS:";
            str += fps;
			device->setWindowCaption(str.c_str());
            lastFPS = fps;
		}
		if(keys[KEY_ESCAPE]){
			break;
		}
	}
}